package greetings

import (
	"bytes"
	"fmt"
	"io"
)

type People interface {
	Speak(string) string
}

type People2 interface {
	Speak2(string) string
}

type Student struct{}

func (s Student) Speak(s2 string) (msg string) {
	panic("implement me")
}

//错误的写法
func (stu *Student) Speak2(think string) (msg string) {
	if think == "a" {
		msg = "this is a message a"
	} else {
		msg = "nothing a"
	}
	return msg
}

func _() {
	var peo People = Student{}
	think := "abc"
	fmt.Println(peo.Speak(think))

	var peo2 People2 = &Student{}
	think = "def"
	fmt.Println(peo2.Speak2(think))
}

//一个容易困扰GO程序员的例子
func InterfaceNilError() {

	var buf *bytes.Buffer
	fmt.Println("buf is true of false ", buf != nil)
	f(buf)
}

// If out is non-nil, output will be written to it.
func f(out io.Writer) {
	// ...do something...
	fmt.Println("buf is true of false ", out != nil)
	if out != nil {
		out.Write([]byte("done!\n"))
	}
}
